import type { RouteRecordRaw } from 'vue-router'
import { appConfig } from '@/config'
import { loadFiles } from '@/utils'
import { RoutesHandler } from '../utils'

const loadRoutes = loadFiles<RouteRecordRaw>

export const routesHandler = new RoutesHandler(
  // 多模块
  [
    // {
    //   path: 'system',
    //   meta: {
    //     title: '系统管理'
    //   },
    //   children: loadRoutes(import.meta.glob('./system/*.ts', { eager: true }))
    // }
  ] as RouteRecordRaw[],
  // 单模块
  // loadRoutes(import.meta.glob('./main/*.ts', { eager: true })),
  appConfig.routesHandlerOptions
)
// console.log(routesHandler)

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: appConfig.routeMainName,
    redirect: {
      name: 'SystemHome'
    }
  },
  //落地页
  {
    path: '/system-home',
    component: () => import('@/views/layout/homeLayout/homeLayout.vue'),
    name: 'SystemHome',
    redirect: {
      name: 'SystemHomeMenu'
    },
    children: [
      {
        path: 'menu',
        name: 'SystemHomeMenu',
        meta: {
          title: '首页'
        },
        component: () => import('@/views/home/menu/menu.vue')
      }
    ]
  },
  {
    path: '/user-menu',
    name: 'UserHomeMenu',
    meta: {
      title: '社会组织首页'
    },
    component: () => import('@/views/userHome/menu/menu.vue')
  },
  //
  // {
  //   path: '/systemSetting',
  //   name: 'SystemSetting',
  //   redirect: {
  //     name: 'Organization'
  //   },
  //   meta: {
  //     title: '系统设置'
  //   },
  //   component: () => import('@/views/layout/layout.vue'),
  //   children: loadRoutes(
  //     import.meta.glob('./systemSetting/*.ts', { eager: true })
  //   )
  // },
  {
    path: '/user',
    redirect: {
      name: appConfig.routeLoginName
    },
    component: () => import('@/views/layout/userLayout/userLayout.vue'),
    children: loadRoutes(import.meta.glob('./user/*.ts', { eager: true }))
  },
  // {
  //   path: '/spotCheck',
  //   redirect: {
  //     name: 'SpotCheck'
  //   },
  //   component: () => import('@/views/layout/layout.vue'),
  //   children: loadRoutes(import.meta.glob('./spotCheck/*.ts', { eager: true }))
  // },
  {
    path: '/ykb/index',
    name: 'YKBYearCheck',
    meta: {
      title: '年检年报'
    },
    component: () => import('@/views/yearCheck/ykb/index.vue')
  },
  {
    path: '/ykb/activity',
    name: 'YKBActive',
    meta: {
      title: '活动录入'
    },
    component: () => import('@/views/yearCheck/ykb/activity.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    meta: {
      needRouteHistory: false,
      name: 'Error404'
    },
    component: () => import('@/views/error/error404.vue')
  },
  {
    path: '/error401',
    meta: {
      name: 'Error401',
      needToken: false
    },
    component: () => import('@/views/error/error401.vue')
  },
  {
    path: '/error10000',
    meta: {
      name: 'Error10000',
      needToken: false
    },
    component: () => import('@/views/error/error10000.vue')
  },
  {
    path: '/phone/active',
    meta: {
      name: 'PhoneActive',
      needToken: false
    },
    component: () => import('@/views/evaluate/activite/phone.vue')
  },
  {
    path: '/phone/activity/list',
    name: 'YKBPhoneActive',
    meta: {
      title: '活动列表'
    },
    component: () => import('@/views/evaluate/activite/activeList.vue')
  },
  {
    path: '/phone/activity/add',
    name: 'YKBPhoneActiveAdd',
    meta: {
      title: '活动新增'
    },
    component: () => import('@/views/evaluate/activite/activeAdd.vue')
  },
  {
    path: '/largeScreen',
    name: 'YKBPhoneActiveAdd',
    meta: {
      title: '大屏',
      needToken: false
    },
    component: () => import('@/views/largeScreen/index.vue')
  },
  {
    path: '/riskDisposal',
    name: 'RiskDisposal',
    meta: {
      title: '社会组织风险处置',
      needToken: true
    },
    component: () => import('@/views/layout/layout.vue'),
    children: [
      {
        path: '/riskDisposal/taskManagement/restructuring',
        name: 'Restructuring',
        meta: {
          title: '任务整改-页面',
          needToken: false
        },
        component: () => import('@/views/riskDisposal/taskManagement/restructuring/restructuring.vue')
      }
    ]
  }
]

export default routes
